package com.rxmvp.rxmvpdemo.base;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.LayoutRes;

import com.rxmvp.rxmvpdemo.AppManager;
import com.rxmvp.rxmvpdemo.base.mvp.IBaseView;
import com.rxmvp.rxmvpdemo.utils.ToastUtil;
import com.trello.rxlifecycle.components.support.RxAppCompatActivity;

import butterknife.ButterKnife;

/**
 * 当不使用presenter时，Activity可以直接继承该类，使用activity的共有方法
 *
 * 作者： huangRZ on 2017/1/21. 15:35
 * 邮箱：917647409@qq.com
 */

public abstract class BaseActivity extends RxAppCompatActivity implements IBaseView {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //把打开的activity添加到定义的栈中管理
        AppManager.addActivity(this);
    }

    @Override
    public void setContentView(@LayoutRes int layoutResID) {
        super.setContentView(layoutResID);
        //必须在设置了contentView之后绑定butterKnife才可以使用butterKnife
        ButterKnife.bind(this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        //activity销毁后，从栈中将该activity移除
        AppManager.finishActivity(this);
    }

    @Override
    public void showShortToast(String msg) {
        ToastUtil.showToast(msg);
    }

    @Override
    public void showLongToast(String msg) {
        ToastUtil.showLongToast(msg);
    }

    @Override
    public void jump2activity(Class clazz) {
        startActivity(new Intent(this, clazz));
    }

}
